package view;

import javax.swing.ComboBoxModel;
import ucm.UCUpdateAirline;

public class Air_User extends javax.swing.JFrame {

    private String[] airline;
    private String[] price;
    private String[] destination;
    private ComboBoxModel cbm;

    /** Creates new form Air_User */
    public Air_User() {
        initComponents();
        Update();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        airlineComboBox = new javax.swing.JComboBox();
        airlineLabel = new javax.swing.JLabel();
        priceLabel = new javax.swing.JLabel();
        priceTextField = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        destinationLabel = new javax.swing.JLabel();
        arriveLabel = new javax.swing.JLabel();
        departLabel = new javax.swing.JLabel();
        aircraftLabel = new javax.swing.JLabel();
        destinationTextField = new javax.swing.JTextField();
        departTextField = new javax.swing.JTextField();
        aircraftTextField = new javax.swing.JTextField();
        priceTextField9 = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        updateButton = new javax.swing.JButton();
        noteTextField = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        update_MenuItem = new javax.swing.JMenuItem();
        enrollMenuItem = new javax.swing.JMenuItem();
        delete_MenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("User");

        airlineComboBox.setEditable(true);
        airlineComboBox.setFont(new java.awt.Font("Arial", 3, 12));
        airlineComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CA1116", "CA1111", "CA1112", "CA1113", "CA1114", "CA1115", "CA1117", "CA1118", "CA1119", "CA1110", "CA1120", "CA1121", "CA1122", "CA1123" }));
        airlineComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                airlineComboBoxActionPerformed(evt);
            }
        });

        airlineLabel.setFont(new java.awt.Font("Arial", 3, 14));
        airlineLabel.setText("Airline");

        priceLabel.setFont(new java.awt.Font("Arial", 3, 14));
        priceLabel.setText("Price");

        priceTextField.setEditable(false);
        priceTextField.setFont(new java.awt.Font("Arial", 3, 14));

        destinationLabel.setFont(new java.awt.Font("Arial", 3, 14));
        destinationLabel.setText("Destination");

        arriveLabel.setFont(new java.awt.Font("Arial", 3, 14));
        arriveLabel.setText("Arrive Time");

        departLabel.setFont(new java.awt.Font("Arial", 3, 14));
        departLabel.setText("Depart Time");

        aircraftLabel.setFont(new java.awt.Font("Arial", 3, 14));
        aircraftLabel.setText("Aricraft");

        destinationTextField.setEditable(false);
        destinationTextField.setFont(new java.awt.Font("Arial", 3, 14));

        departTextField.setEditable(false);
        departTextField.setFont(new java.awt.Font("Arial", 3, 14));

        aircraftTextField.setEditable(false);
        aircraftTextField.setFont(new java.awt.Font("Arial", 3, 14));

        priceTextField9.setEditable(false);
        priceTextField9.setFont(new java.awt.Font("Arial", 3, 14));

        updateButton.setFont(new java.awt.Font("宋体", 3, 14));
        updateButton.setText("Update");
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        noteTextField.setEditable(false);
        noteTextField.setFont(new java.awt.Font("Arial", 3, 14));

        jMenu1.setText("File");

        update_MenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        update_MenuItem.setText("Update");
        update_MenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                update_MenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(update_MenuItem);

        enrollMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        enrollMenuItem.setText("Enroll");
        enrollMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enrollMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(enrollMenuItem);

        delete_MenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        delete_MenuItem.setText("Delete");
        jMenu1.add(delete_MenuItem);
        jMenu1.add(jSeparator1);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setText("Exit");
        jMenu1.add(exitMenuItem);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(airlineLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(airlineComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24)
                .addComponent(priceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(priceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 564, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(destinationLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                    .addComponent(arriveLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(priceTextField9)
                    .addComponent(destinationTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(aircraftLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                    .addComponent(departLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(departTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aircraftTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 564, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(updateButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(noteTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(airlineComboBox)
                    .addComponent(airlineLabel)
                    .addComponent(priceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(priceLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(destinationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(destinationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(departTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(departLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(arriveLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(priceTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aircraftLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aircraftTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(139, 139, 139)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(updateButton)
                    .addComponent(noteTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void update_MenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_update_MenuItemActionPerformed
        Update();
}//GEN-LAST:event_update_MenuItemActionPerformed

    private void enrollMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enrollMenuItemActionPerformed
}//GEN-LAST:event_enrollMenuItemActionPerformed

    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
        Update();
    }//GEN-LAST:event_updateButtonActionPerformed

    private void airlineComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_airlineComboBoxActionPerformed
        /*int num = airlineComboBox.getSelectedIndex();
        this.priceTextField.setText(price[0]);
        this.destinationTextField.setText(destination[0]);*/
    }//GEN-LAST:event_airlineComboBoxActionPerformed

    public void Update() {
        String[] str;
        String[] s = new String[3];
        if ((str = new UCUpdateAirline().run()) != null) {
            this.airlineComboBox.removeAllItems();
            for (int count = 0; count < str.length; count++) {
                s = str[count].split(";");

                airline = new String[str.length];
                price = new String[str.length];
                destination = new String[str.length];

                airline[count] = s[0];
                this.airlineComboBox.addItem(airline[0]);
                price[count] = s[1];
                this.priceTextField.setText(price[0]);
                destination[count] = s[2];
                this.priceTextField.setText(destination[0]);
            }
        } else {
            this.noteTextField.setText("Nothing can be updated from database.");
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Air_User().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel aircraftLabel;
    private javax.swing.JTextField aircraftTextField;
    private javax.swing.JComboBox airlineComboBox;
    private javax.swing.JLabel airlineLabel;
    private javax.swing.JLabel arriveLabel;
    private javax.swing.JMenuItem delete_MenuItem;
    private javax.swing.JLabel departLabel;
    private javax.swing.JTextField departTextField;
    private javax.swing.JLabel destinationLabel;
    private javax.swing.JTextField destinationTextField;
    private javax.swing.JMenuItem enrollMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField noteTextField;
    private javax.swing.JLabel priceLabel;
    private javax.swing.JTextField priceTextField;
    private javax.swing.JTextField priceTextField9;
    private javax.swing.JButton updateButton;
    private javax.swing.JMenuItem update_MenuItem;
    // End of variables declaration//GEN-END:variables
}
